﻿using System;

namespace ListExer
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //整形List
            GenericList<int> intList = new GenericList<int>();
            for(int x = 0; x < 10; x++)
            {
                intList.Add(x);
            }
            for(Node<int> node = intList.Head; node != null; node = node.Next)
            {
                Console.WriteLine(node.Data);
            }
            Console.WriteLine("通过ForEach函数遍历输出");
            //对于每一个x，打印x，实现打印链表元素
            intList.ForEach(x => Console.WriteLine(x));
            //求和，对于每一个x，加到sumInt上面
            int sumInt = 0;
            intList.ForEach(x => sumInt+=x);
            Console.WriteLine("sumInt为" + sumInt); 
            //求链表中的最大值
            int maxInt = 0;
            intList.ForEach(x => maxInt = maxInt < x ? x : maxInt);
            Console.WriteLine("maxInt为" + maxInt);
            //求链表中的最小值
            int minInt = 1000000;
            intList.ForEach(x => minInt = minInt > x ? x : minInt);
            Console.WriteLine("minInt为" + minInt);
            //字符串型List
            GenericList<string> strList = new GenericList<string>();
            for(int x = 0; x < 10; x++)
            {
                strList.Add("str" + x);
            }
            for(Node<string> node = strList.Head; node != null; node = node.Next)
            {
                Console.WriteLine(node.Data);
            }
            Console.WriteLine("通过ForEach函数遍历输出");
            //对于每一个x，打印x，实现打印链表元素
            strList.ForEach(x => Console.WriteLine(x));
            //求和，对于每一个字符串x的长度，加到sumInt上面
            int sumString = 0;
            strList.ForEach(x => sumString += x.Length);
            Console.WriteLine("sumString为" + sumString);
            //求链表中的最大值
            int maxString = 0;
            strList.ForEach(x => maxString = maxString < x.Length ? x.Length : maxString);
            Console.WriteLine("maxString为" + maxString);
            //求链表中的最小值
            int minString = 1000000;
            strList.ForEach(x => minString = minString > x.Length ? x.Length : minString);
            Console.WriteLine("minString为" + minString);
        }
    }
}
